const setStorage = (key, data) => {
  uni.setStorage({
    key,
    data,
    success() {
      console.log(`存储${key}->${data}成功`);
    },
    fail(err) {
      console.log(`存储${key}->${data}失败，错误是${err}`);
    },
  });
};
const setStorageSync = (key, value) => {
  try {
    uni.setStorageSync(key, value);
    console.log(`同步存储${key}->${value}成功`);
  } catch (err) {
    // error
    console.log(`同步存储${key}->${value}失败，错误是${err}`);
  }
};
const getStorage = (key) => {
  let value = null;
  let error = "";
  uni.getStorage({
    key,
    success: function (res) {
      value = res.data;
      console.log(`获取存储${key}->${value}成功`);
    },
    fail: function (err) {
      error = err;
      console.log(`获取存储${key}失败,错误是${error}`);
    },
  });
  return {
    value,
    error,
  };
};
const getStorageSync = (key) => {
  let value;
  let error = "";
  try {
    value = uni.getStorageSync(key);
    if (value) {
      console.log(`同步获取${key}->${value}成功`);
    }
  } catch (e) {
    // error
    error = e;
    console.log(`同步获取存储${key}失败,错误是${error}`);
  }
  return {
    value,
    error,
  };
};
const removeStorage = (key) => {
  uni.removeStorage({
    key,
    success: function (res) {
      console.log(`删除存储${key}成功!`);
    },
    fail(error) {
      console.log(`删除存储${key}失败,错误是${error}`);
    },
  });
};
export default {
  setStorage,
  setStorageSync,
  getStorage,
  getStorageSync,
  removeStorage,
};
